﻿using System;

namespace ArcEngine
{
	/// <summary>
	/// Defines the log level
	/// </summary>
	public enum LogLevel
	{
		/// <summary>
		/// 
		/// </summary>
		Debug,

		/// <summary>
		/// 
		/// </summary>
		ToDo,

		/// <summary>
		/// 
		/// </summary>
		Info,

		/// <summary>
		/// 
		/// </summary>
		Warning,

		/// <summary>
		/// 
		/// </summary>
		Error,

		/// <summary>
		/// 
		/// </summary>
		Fatal
	};


	/// <summary>
	/// Event log class
	/// </summary>
	public class LogEventArgs : EventArgs
	{
		/// <summary>
		/// 
		/// </summary>
		/// <param name="lvl"></param>
		/// <param name="msg"></param>
		/// <param name="trace"></param>
		public LogEventArgs(LogLevel lvl, string msg, string trace)
		{
			this.level = lvl;
			this.message = msg;
			this.trace = trace;
		}

		/// <summary>
		/// Type of log info
		/// </summary>
		public LogLevel Level
		{
			get
			{
				return level;
			}
		}
		LogLevel level;


		/// <summary>
		/// Message of the log
		/// </summary>
		public string Message
		{
			get
			{
				return message;
			}
		}
		string message;


		/// <summary>
		/// Stack of the message
		/// </summary>
		public string Trace
		{
			get
			{
				return trace;
			}
		}
		string trace;
	}


	/// <summary>
	///  Main logging class
	/// </summary>
	public class Log
	{

		/// <summary>
		/// 
		/// </summary>
		static public event EventHandler<LogEventArgs> OnEvent;



		#region Methods

		/// <summary>
		/// Send an event
		/// </summary>
		/// <param name="e"></param>
		static public void Send(LogEventArgs e)
		{

			if (e.Level == LogLevel.Error)
				errorCount++;
			else if (e.Level == LogLevel.Warning)
				warningCount++;


			// Writes it to the console
			Terminal.Log(e);

			// Send the event
			if (OnEvent != null)
				OnEvent(null, e);
		}


		/// <summary>
		/// Clear the log history
		/// </summary>
		static public void Clear()
		{
			Terminal.Clear();

			errorCount = 0;
			warningCount = 0;
		}

		#endregion




		#region Properties


		/// <summary>
		/// Numbers of error
		/// </summary>
		static public int ErrorCount
		{
			get
			{
				return errorCount;
			}
		}
		static int errorCount;





		/// <summary>
		/// Number of warning
		/// </summary>
		static public int WarningCount
		{
			get
			{
				return warningCount;
			}
		}
		static int warningCount;

		#endregion
	}

}
